package com.wgt;

/**
 * Created by wgt on 2017/5/31.
 */
public class CutString {

    public static void main(String[] args) throws Exception{
        String str = "我a爱中华abc我爱传智def";
        int num = trimGBK(str.getBytes("utf-8"),7);
        System.out.println(str.substring(0,num) );
    }


    public static int  trimGBK(byte[] buf,int n){
        int num = 0;
        boolean bChineseFirstHalf = false;
        for(int i=0;i<n;i++)
        {
            if(buf[i]<0 && !bChineseFirstHalf){
                bChineseFirstHalf = true;
            }else{
                num++;
                bChineseFirstHalf = false;
            }
        }
        return num;
    }

}
